package com.fh.fruit.controller.order;

import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.fh.controller.base.BaseController;
import com.fh.entity.Page;
import com.fh.fruit.entity.order.Order;
import com.fh.fruit.service.order.OrderManager;
import com.fh.util.Jurisdiction;
import com.fh.util.PageData;

@Controller
@RequestMapping(value = "/order")
public class OrderController extends BaseController {

	@Resource(name = "orderService")
	private OrderManager orderService;

	@RequestMapping(value = "/listOrders")
	public ModelAndView listOrders(Page page) throws Exception {
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		// 订单成交时间范围
		String start = pd.getString("closingTimeStart"); // 最早订单时间
		String end = pd.getString("closingTimeEnd");// 最近订单时间
		pd.put("start", start);
		pd.put("end", end);
		pd.put("phone", pd.getString("phone"));
		String status = pd.getString("select");
		if (status != null && !"".equals(status)) {
			pd.put("status", status);
		} else {
			pd.put("status", "");
		}
		page.setPd(pd);
		List<Order> orderList = orderService.listOrders(page); // 列出订单列表
		mv.setViewName("farm/order/order_list");
		mv.addObject("orderList", orderList);
		mv.addObject("pd", pd);
		mv.addObject("QX", Jurisdiction.getHC()); // 按钮权限
		return mv;
	}
}
